package controllers;

import java.util.ArrayList;

import javax.swing.text.View;

import play.data.validation.Required;
import play.mvc.Controller;
import play.mvc.With;
import models.Boat;
import models.News;

@With(Secure.class) 
public class Boats extends Controller{
	
	public static void AddBoat(@Required String Desc)
	{
		if(!validation.hasErrors())
		{
			Boat boat = new Boat(Desc);
			boat.save();
			CreatedBoat(boat);
	
		}
		else
		{
			
			render();
		}
		
	}

	public static void CreatedBoat(Boat boat) {
		render(boat);
		
	}
	public static void ViewAllBoats(){
		ArrayList boatlist=(ArrayList) Boat.findAll();
		render(boatlist);
		
	}
	public static void ViewBoat(long id){
		Boat x = Boat.findById(id);
		render(x);
		
	}
	public static void DeleteBoat(long id)
	{
		Boat boat = Boat.findById(id);
		boat.delete();
		ViewAllBoats();
	}
	public static void EditBoat(long id)
	{
		Boat x = Boat.findById(id);
		render(x, id);
	}
	public static void Edit(long id , String Desc)
	{
		if(Desc!=null)
		{
		Boat x = Boat.findById(id);
		x.Desc=Desc;
		x.save();
		ViewBoat(id);
		}
		else{
			EditBoat(id);
		}
		
	}

}
